package com.huanzhidadi.logaspect.controller;

import com.huanzhidadi.logaspect.annotation.Log;
import com.huanzhidadi.logaspect.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "logClass")
@RestController
@RequestMapping(value = "logClass")
@Slf4j
@Log(title = "类级日志管理", businessType = BusinessType.GRANT)
public class LogClassController {

    @ApiOperation(value = "日志记录")
    @RequestMapping(value = "/getLog", method = RequestMethod.POST)
    public Map<String, String> getLog(@RequestBody Map<String, String> paramMap) {
        Map<String, String> resultMap = new HashMap<>();
        resultMap.putAll(paramMap);
        resultMap.put("result", "ok");
        return resultMap;
    }

    @ApiOperation(value = "另一个日志记录")
    @RequestMapping(value = "/getOtherLog", method = RequestMethod.POST)
    public Map<String, String> getOtherLog(@RequestBody Map<String, String> paramMap) {
        Map<String, String> resultMap = new HashMap<>();
        resultMap.putAll(paramMap);
        resultMap.put("result", "ok");
        if ("0".equals(paramMap.get("aa"))) {
            int i = 1 / Integer.valueOf(paramMap.get("aa"));
        }
        return resultMap;
    }

    @ApiOperation(value = "错误日志记录")
    @RequestMapping(value = "/getErrorLog", method = RequestMethod.POST)
    public Map<String, String> getErrorLog(@RequestBody Map<String, String> paramMap) {
        Map<String, String> resultMap = new HashMap<>();
        resultMap.putAll(paramMap);
        resultMap.put("result", "ok");

        return resultMap;
    }
}
